---
title: Clearing & Resetting
layout: page
pageOrder: 4
section: 'Mock Server'
subsection: true
sitemap:
  priority: 0.7
  changefreq: 'monthly'
  lastmod: 2018-11-16T16:00:00+01:00
---

<p>MockServer has internal state:</p>

<ul>
    <li><strong>recorded requests</strong></li>
    <li><strong>active expectations</strong></li>
    <li><strong>recorded expectations</strong></li>
    <li><strong>logs</strong></li>
</ul>

<p>State can be <strong>cleared</strong> from MockServer selectively:</p>
<ul>
    <li>use <strong>type</strong> to select with type of state to clear</li>
    <li>use a <strong>request matcher</strong> to clear matching items</li>
</ul>

<button id="button_client_clear" class="accordion">clear everything that matches request matcher</button>
<div class="panel">
    <button class="accordion inner">Java: MockServerClient</button>
    <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST")
);</code></pre>
    </div>
    <button class="accordion inner">JavaScript: mockserver-client</button>
    <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .clear({
    'path': '/some/path'
  })
  .then(
    function () {
      console.log("cleared state that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );</code></pre>
    </div>
    <button class="accordion inner">REST API</button>
    <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/clear" -d '{
    "path": "/some/path"
}'</code></pre>
    </div>
</div>
<button id="button_client_clear_logs_by_req" class="accordion">clear recorded requests and logs that matches request matcher</button>
<div class="panel">
    <button class="accordion inner">Java: MockServerClient</button>
    <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST"),
    ClearType.LOG
);</code></pre>
    </div>
    <button class="accordion inner">JavaScript: mockserver-client</button>
    <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .clear({
    'path': '/some/path'
  }, 'LOG')
  .then(
    function () {
      console.log("cleared recorded requests and logs that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );</code></pre>
    </div>
    <button class="accordion inner">REST API</button>
    <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/clear?type=LOGS" -d '{
    "path": "/some/path"
}'</code></pre>
    </div>
</div>
<button id="button_client_clear_expectations_by_req" class="accordion">clear expectations that matches request matcher</button>
<div class="panel">
    <button class="accordion inner">Java: MockServerClient</button>
    <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST"),
    ClearType.EXPECTATIONS
);</code></pre>
    </div>
    <button class="accordion inner">JavaScript: mockserver-client</button>
    <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .clear({
    'path': '/some/path'
  }, 'EXPECTATIONS')
  .then(
    function () {
      console.log("cleared expectations that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );</code></pre>
    </div>
    <button class="accordion inner">REST API</button>
    <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/clear?type=EXPECTATIONS" -d '{
    "path": "/some/path"
}'</code></pre>
    </div>
</div>

<p>MockServer can be <strong>reset</strong> completely, as follows:</p>

<button id="button_client_reset" class="accordion">reset everything</button>
<div class="panel">
    <button class="accordion inner">Java: MockServerClient</button>
    <div class="panel">
        <pre class="prettyprint lang-java code"><code class="code">new MockServerClient("localhost", 1080).reset();</code></pre>
    </div>
    <button class="accordion inner">JavaScript: mockserver-client</button>
    <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .reset()
  .then(
    function () {
      console.log("reset all state");
    },
    function (error) {
      console.log(error);
    }
  );</code></pre>
    </div>
    <button class="accordion inner">REST API</button>
    <div class="panel">
        <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/reset</code></pre>
    </div>
</div>
